package com.csr.csrcheck.controller;

import com.csr.csrcheck.controller.ex.CompanyException;
import com.csr.csrcheck.pojo.Product_recall;
import com.csr.csrcheck.service.impl.RecallServiceImpl;
import com.csr.csrcheck.util.JsonResult;
import com.csr.csrcheck.util.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping({"recall"})
public class RecallConntroller extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(com.csr.csrcheck.controller.RecallConntroller.class);

    @Resource
    private RecallServiceImpl recallService;

    @GetMapping({"recalllist"})
    public JsonResult<List<Product_recall>> getlist() {
        List<Product_recall> list = this.recallService.getlist();
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @RequestMapping({"recall"})
    public JsonResult<Object> productrecall(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "5") int pageSize, String company_name, String product_name, String product_t_name) {
        PageResult pageResult = this.recallService.getlistpage(pageNum, pageSize, company_name, product_name, product_t_name);
        if (pageResult == null)
            throw new CompanyException("");
                    log.info("productrecall----------------------------------------->pageNum:" + pageNum);
        log.info("productrecall----------------------------------------->pageSize:" + pageSize);
        log.info("productrecall----------------------------------------->company_name:" + company_name);
        log.info("productrecall----------------------------------------->product_name:" + product_name);
        log.info("productrecall----------------------------------------->product_t_name:" + product_t_name);
        return new JsonResult(Integer.valueOf(0), "json", pageResult);
    }
}
